package com.asa.base

import android.app.Application
import android.view.View
import androidx.lifecycle.*

open class BaseViewModel:ViewModel(),ViewModelLifecycle {

    lateinit var application:Application

    protected lateinit var lifecycleOwner: LifecycleOwner
    companion object{
        @JvmStatic
        fun<T : BaseViewModel> createViewModelFactory(viewModel: T):ViewModelProvider.Factory{
            return ViewModelFactory(viewModel)
        }
    }

    class ViewModelFactory(private val viewModel: BaseViewModel):ViewModelProvider.Factory{
        override fun <T : ViewModel?> create(modelClass: Class<T>): T {
            return viewModel as T
        }
    }

    override fun onAny(owner: LifecycleOwner, event: Lifecycle.Event) {
        lifecycleOwner = owner
    }

    override fun onCreate() {

    }

    override fun onStart() {

    }

    override fun onResume() {

    }

    override fun onPause() {

    }

    override fun onStop() {

    }

    override fun onDestroy() {

    }
}
